#include <cstdio>
#include <cmath>

long long msqr( long long a )
{
    long long l = 0, r = 3037000499LL, mid;
    while ( l < r )
    {
        mid = ( l + r ) / 2;
        if ( mid * mid < a )
            l = mid + 1;
        else
            r = mid;
    }
    if ( l * l != a )
        return l - 1;
    return l;
}

long long calc( long long a )
{
    long long d, p;
    d = a / 2;
    if ( a >= 2 ) d--;
    p = msqr( a );
    p--;
    if ( p <= 0 )
        return d;
    d -= ( p + 1 ) / 2;
    d += p / 2;
    return d;
}

int main( )
{
    long long a, b, d1, d2;
    int t;
    scanf("%d", &t);
    while ( t-- )
    {
        scanf("%I64d%I64d", &a, &b);
        d1 = calc( a - 1 );
        d2 = calc( b );
        printf("%I64d\n", d2 - d1);
    }
    return 0;
}
